package org.example;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;

import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class CSVReaderExample {

    public static void main(String[] args) {
        String csvFile = "/path/to/your/csvfile.csv"; // 替换为你的CSV文件路径
        try {
                FileReader reader = new FileReader(csvFile, StandardCharsets.UTF_8);
                Iterable<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(reader);

            for (CSVRecord record : records) {
                String field1 = record.get("Header1"); // 替换为你的CSV文件的实际列名
                String field2 = record.get("Header2"); // 替换为你的CSV文件的实际列名
                // ... 解析其他字段 ...

                System.out.println("Field1: " + field1 + ", Field2: " + field2); // 输出字段值
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
